﻿/************************************************/
//功能说明:adc主框架脚本
//创建时间:2011-6-10
//创建人:zche
/************************************************/

var adc = function () {
    return {
        //初始命令按钮
        initCommand: function () {
            //回车键支持
            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    $(".click").each(function () {
                        this.click();
                    })
                }
            });
            //未postback前不重复提交
            $(".once").click(function () {
                var _this = $(this);
                setTimeout(function () {
                    _this.attr("disabled", "disabled");
                }, 0);
            })
            //linkButton
            $(".ligerui-linkbutton").linkbutton({ plain: true });
        },
        /*
        adc.adjustHeight("框架页Id",1000);//非跨域调整父框架页高度，可延伸时设置。
        */
        adjustHeight: function (_iframe, time) {
            if (_iframe == "" || undefined == _iframe) {
                _iframe = $("#contextPage", parent.document);
            }
            if (time == "" || undefined == time) {
                time = 1000;
            }
            var inter = setInterval(function () {
                var height;
                if (_iframe[0].contentDocument == null || _iframe[0].contentDocument == undefined || _iframe[0].contentDocument.body == null) {
                    height = $(_iframe[0].contentWindow.document.body).height();
                } else {
                    height = $(_iframe[0].contentDocument).height();
                }
                if ($.browser.opera || $.browser.safari) {
                    //
                }
                if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
                    height = height + 20;
                }
                if (null == height) {
                    height = 500;
                }
                _iframe.height(height);
            }, time);
        },
        /*
        adc.adjustCenter();//弹出页自动居中
        */
        adjustCenter: function () {
            var width = $(document).width();
            var sWidth = screen.width;
            var left = sWidth - ((sWidth - width) / 2 + width);
            if (left < 0) {
                left = 0;
            }
            try {
                window.moveTo(left, 0);
            } catch (e) {
                //处理自动居中时选中窗体报错问题。
            }
        },
        open: function (options) {
            var defaults = {
                //参数
                url: "",
                width: 600,
                height: 350,
                modal: true
            }
            var options = $.extend(defaults, options);
            var _url = options.url;
            var _width = options.width;
            var _height = options.height;
            var _modal = options.modal;
//            if (_modal) {
//                alert(_modal);
//                window.showModalDialog(_url, "", "dialogWidth:" + _width + "px;dialogHeight:" + _height + "px;scroll:no;status:no");
//            } else {
//                alert("fff1111");
                window.open(_url, "", "width=" + _width + ",height=" + _height + ",toolbar=no,resizable=yes,scrollbars=yes,location=no, status=no");
//            }
        },
        showGridError: function (options) {
            var defaults = {
                grid: null,
                msg: ""
            }
            var options = $.extend(defaults, options);
            var _grid = options.grid;
            var _msg = options.msg;
            var _fnReflash = function () {
                var grid = $(_grid).ligerGetGridManager();
                grid.loadData();
            }
            var _errordiv = "<div class='error'><span class='error_content'>" + _msg + "<a href=\"#\" id='btn_reflash'>重试</a></span></div>";
            if ($(".error", $(_grid)).length == 0) {
                $(".l-grid-body", $(_grid)).append(_errordiv);
                $("#btn_reflash", $(_grid)).click(function () {
                    _fnReflash();
                })
            }
        },
        showGridMsg: function (options) {
            var defaults = {
                grid: null,
                msg: "未找到相关数据！"
            }
            var options = $.extend(defaults, options);
            var _grid = options.grid;
            var _msg = options.msg;
            var _errordiv = "<div class='error'><span class='error_content'>" + _msg + "</span></div>";
            if ($(".error", $(_grid)).length == 0) {
                $(".l-grid-body", $(_grid)).append(_errordiv);
            }
        }
    };
} ();


$(function () {
    adc.initCommand();
})
 











